
#include "accounts_admin.h"


accounts_admin *accounts_admin::instance=NULL;

accounts_admin *accounts_admin::get_accounts_admin()
	{
		if (instance==NULL) instance = new accounts_admin();
		return instance;
	};

accounts_admin::accounts_admin()
{
	members_counter = 0;
	n_members_counter =0;
};

bool accounts_admin::check_availability(int phone)
{
	if (accounts_admin::search_m(phone))
	{
		if (accounts_admin::get_tenant(phone)->rents_now)
		{
			return false;
		}
	}
	return true;
};

customer *accounts_admin::get_tenant(int phone)
{
	if(search_m(phone))
	{
		return &members[phone];
	}
	cout<<endl<<"Please, type the customer's name: "<<endl;
	string name__; char a[100]; getchar(); gets_s(a);
	name__=a;
	if(add_n(name__,phone))
		return &n_members[phone];

	return NULL;
};


// Michael


bool accounts_admin::search_m(int phone_)
{
	if(members_counter >0)
	{ if(members.find(phone_) != members.end())
	{return true;}
	else { return false;}
	}
	else if (members_counter == 0)
	{return false;}

	return false;
}

bool accounts_admin::add_m(string name_ , int phone_ , string address_ , string email_ , int credit_card_)
{
	bool a = search_m(phone_);
	if(a == false)
	{
		members[phone_] = member(name_ , phone_ , address_ , email_ , credit_card_);
		members_counter++;
		return true;           // true if added
	}
	else return false;   // false if this phone is already member 

}

bool accounts_admin::search_n(int phone_)
{
	if(n_members_counter > 0)
	{ if( n_members.find(phone_) != n_members.end())
	{ return true;}
	else { return false;}
	}
	else if(n_members_counter == 0)
	{return false ;}

	return false;
}

bool accounts_admin::add_n(string name_ , int phone_)
{
	bool a = search_n(phone_);
	if (a == false)
	{
	n_members[phone_] = n_member(name_ , phone_);
	n_members_counter++;
	return true;  // added to non members map
	}
	else return false; // this non member mawgood
}

void accounts_admin::delete_m(int phone_)
{
	members.erase(phone_);
}

void accounts_admin::delete_n(int phone_)
{
	n_members.erase(phone_);
}

void accounts_admin::update_account(string name_ , int phone_ , string address_ , string email_ , int credit_card_)
{
	members[phone_].set_name(name_);
	members[phone_].set_credit_card(credit_card_);
	members[phone_].set_email(email_);
	members[phone_].set_address(address_);
};

accounts_admin::~accounts_admin(void)
{
}